package work.jame.blog.controller;


import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import work.jame.blog.framework.limit.RequestLimit;
import work.jame.blog.framework.result.Result;
import work.jame.blog.service.UserRelationService;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Jame
 * @since 2023-05-14
 */
@RestController
@RequestMapping("/userRelation")
public class UserRelationController {

    @Autowired
    private UserRelationService userRelationService;


    @ApiOperation("关注用户")
    @GetMapping("/followUser")
    @RequestLimit(value = 10, timeUnit = TimeUnit.MINUTES)
    public Result<?> followUser(@RequestParam("followUserId") Long followUserId){
        if(userRelationService.followUser(followUserId)){
            return Result.succeedMessage("关注成功!");
        }
        return Result.succeedMessage("关注失败!");
    }

    @ApiOperation("取关用户")
    @GetMapping("/cancelFollowUser")
    @RequestLimit(value = 10, timeUnit = TimeUnit.MINUTES)
    public Result<?> cancelFollowUser(@RequestParam("followUserId") Long followUserId){
        if(userRelationService.cancelFollowUser(followUserId)){
            return Result.succeedMessage("取关成功");
        }
        return Result.succeedMessage("取关失败");
    }


}
